<template>
  <div class="goodlist" >
    <van-search placeholder="请输入搜索关键词" show-action @search="onSearch">
      <template #action>
        <div style="display:flex;">
       <van-icon size="25" name="qr" color="white"/>
        </div>
      </template>
    </van-search>
    <van-tabbar :fixed="false" active-color="#fc4141">
      <van-tabbar-item>{{ $route.query.title }} </van-tabbar-item>
      <van-tabbar-item @click="changePrice">{{condition.priceOrder=='des'?'价格降序':'价格升序'}}</van-tabbar-item>
      <van-tabbar-item>销量</van-tabbar-item>
      <van-tabbar-item>新品</van-tabbar-item>
    </van-tabbar>

    <!-- 内容展示 -->
    <div class="product-box" v-if="productList">
      <router-link :to="`detail/${item.id}`" tag="div" class="product-conent" v-for="item in productList" :key="item.id">
        <div class="img-box">
          <div class="product-img">
              <img :src="item.image" >
          </div>
        </div>
        <div style="padding:0px 5px">
        <div class="product-title">{{item.store_name}}</div>
        <div class="product-name">￥{{item.price}}</div>
        <div class="product-more">
          <div class="product-price">￥{{item.vip_price}}</div>
          <div class="product-icon">
                      <img
              src=""
            />
          </div>
          <div class="product-sell">已售{{item.sales}}</div>
      </div>

        </div>
    </router-link>
  </div>

  <!-- 数据无内容则显示推荐 -->
  <div class="recommend" v-if="productList.length==0">
      <div class="recommend-box">
        <div class="box">
            <img src="http://47.115.51.185/h5/img/noCart.6f2abfef.png">
        </div>
      <Recommend :productId='searchResult'></Recommend>
      </div>
    </div>
  </div>
</template>

<script>
import Recommend from '@/components/Recommend'
export default {
  props: {},
  data() {
    return {
      //   查询条件
      condition: {
        page: 1,
        limit: 10,
        keyword: "",
        sid: 0, //商品id
        news: 0, //展示新品
        priceOrder: '', //价格 cas升序 desc降序
        salesOrder: '' //销量 asc升序 desc降序
      },

      productList: [],

      // 推荐内容
      searchResult:[]
    
    };
  },
  created() {
    this.getProduct()
      // 推荐
       this.axios("api/products",).then((res) => {
        this.searchResult = res.data.data;
      });
  },
  methods: {
    changePrice(){
        if(this.condition.priceOrder=='desc'){
          this.condition.priceOrder='asc';
        }else{
          this.condition.priceOrder='desc'
        }
        this.getProduct()
        // console.log(111);
    },
    onSearch() {},
    getProduct(){
    this.condition.sid = this.$route.query.id;
    this.axios
      .get("/api/products", {
        params: this.condition,
      })
      .then((res) => {
        if (res.data.status == 200) {
          this.productList = res.data.data;
          // console.log(res);
        }
      });
    }
  },
  components:{
    Recommend
  }
};
</script>

<style lang="less" scoped>
.van-search{
  background-color: #fc4141;
    padding: 6px;

  .van-search__content{
    border-radius: 16px;
  }
}
.product-box {
  background-color: rgb(245, 245, 245);
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  // justify-content: space-around;
  justify-content: space-between;
  .product-conent {
    width: 45%;
    background-color: #fff;
    margin: 9px;
    // padding: 0px 13px;
    border-radius: 5px;
    overflow: hidden;
    .img-box {
      width: 100%;
      img {
        // width: 172px;
        width:100%;
        height: 172px;
        display: block;
      }
    }
    .product-title {
      // color: #888;
      text-align: left;
      width: 100%;
      text-overflow: ellipsis;
      white-space: nowrap;
      overflow: hidden;
    }
    .product-name {
      color: #fc4141;
      font-size: 16px;
      font-weight: 700;
    }
    .product-more {
      display: flex;
      font-size: 11px;
      align-items: center;
      padding-bottom: 10px;
      .product-price {
        font-weight: 500;
      }
      .product-icon {
        width: 23px;
        height: 10.5px;
        margin-left: 5px;
        img {
          width: 100%;
          height: 100%;
          display: block;
        }
      }
      .product-sell {
        color: #999;
        margin-left: auto;
      }
    }
  }
}
</style>